package com.zr.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.zr.model.User;
import com.zr.service.PointService;

@Controller
@Scope(value = "prototype")
public class PointAction extends ActionSupport implements ServletResponseAware, SessionAware, ServletRequestAware {

	private HttpServletRequest req; // HttpServletRequest鍨嬪彉閲弐equest澹版槑
	private HttpServletResponse resp; // HttpServletResponse鍨嬪彉閲弐esponse澹版槑
	private Map sion; // HttpSession鍨嬪彉閲弒ession澹版槑

	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.resp = response;
	}

	@Override
	public void setSession(Map<String, Object> session) {
		this.sion = session;
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.req = request;
	}

	@Resource
	private PointService pointService;
	
	private int page;
	private int rows;
	public Integer getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public Integer getRows() {
		return rows;
	}
	public void setRows(int rows) {
		this.rows = rows;
	}
	
	//閰嶉�佺偣LIST
	public void getPointList() {
		resp.setCharacterEncoding("UTF-8");
		User u = (User) sion.get("user");
		JSONObject js = pointService.findAllPoint(page, rows);
		PrintWriter pw;
		try {
			pw = resp.getWriter();
			pw.write(js.toString());
			pw.flush();
			pw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
